import esp32
import machine
import time
import sys
import uasyncio as asyncio
from machine import Pin

relay1 = Pin(8, Pin.OUT)    # create output pin on GPIO0
relay2 = Pin(11, Pin.OUT)    # create output pin on GPIO0
relay3 = Pin(6, Pin.OUT)    # create output pin on GPIO0
# relay1.off()
# relay2.off()
# relay3.off()
def   test_relay():
    for i in range(20):
        print("relay1 "+str(i))
        relay1.on()
        time.sleep_ms(1000)
        relay1.off()
        time.sleep_ms(1000)
       #print("relay2 "+str(i))
       #relay2.on()
       #time.sleep_ms(1000)
       #relay2.off()
       #time.sleep_ms(1000)
       #print("relay3 "+str(i))
       #relay3.on()
       #time.sleep_ms(1000)
       #relay3.off()
       #time.sleep_ms(1000)

    relay1.off()
    relay2.off()
    relay3.off()
def  show_info():
    print("System Info:")
    # For standard ESP32
    temp_f = esp32.mcu_temperature()
    # Convert to Celsius
    temp_c = (temp_f - 32) * 5 / 9
    print("inner temperature: {:.2f}C ({:.2f}F)".format(temp_c, temp_f))


def  relay_reset_ctrl():
    # Set GPIO pin 13 as output
    log_pin = relay1# 12 for log+gnd
    pwr_pin = relay2# 13 for main power

    pwr_pin.value(1) # Turn off main power
    time.sleep(2)  # Delay
    log_pin.value(1) # Ground log
    time.sleep(1)  # Delay
    pwr_pin.value(0) # Turn on main power
    time.sleep(1)  # Delay
    print("Normal reset completed")

if __name__ == '__main__':
    # show_info()
    relay_reset_ctrl()

    # Run the event loop if it was successfully created
    while True:
        try:
            # Run the event loop forever
            # loop.run_forever()
            print("ctrl+c to exit")
            show_info();
            time.sleep(5)  # Delay
        except KeyboardInterrupt:
            print("Program terminated by user")

